package com.gml.jdk.proxy.statics;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : StudentLeader
 * @Description : 班长
 * @Author : gml
 * @Date: 2020-10-20 15:52
 */
public class StudentLeader implements Person {

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(Student student) {
        if (null == this.studentList){
            this.studentList = new ArrayList<>();
        }
        this.studentList.add(student);
    }

    private List<Student> studentList;

    @Override
    public void giveMoney(int money) {
        System.out.println("班长开始收班费---");
        System.out.println("上次班费还有剩余10块钱");
        studentList.forEach(student -> student.giveMoney(money - 10));
        System.out.println("班长收费完毕");
    }

    public static void main(String[] args) {
        //被代理的学生
        Student student1 = new Student("张三");
        Student student2 = new Student("李四");
        //生成代理对象
        StudentLeader studentLeader = new StudentLeader();
        studentLeader.setStudentList(student1);
        studentLeader.setStudentList(student2);

        //班长开始收费
        studentLeader.giveMoney(50);
    }
}
